import LayerMgr from "./view/LayerMgr"
import PanelMgr from "./view/PanelMgr"
import UIMgr from "./view/UIMgr"


/**
 * @description 框架入口
 * @author mirahs
 * @email 2892727493@qq.com
 */
export default class App {
    // 主UI(进入主UI时会清空当前打开的所有UI记录)
    private static _uiMain: string = 'UIMain'
    // view 的分组(如果场景有多相机, 要设置 view 的分组为 UI摄像机的分组)
    private static _viewGroup: string = 'default'


    // 初始化
    public static init(uiMain?: string, viewGroup?: string) {
        if (uiMain) this._uiMain = uiMain
        if (viewGroup) this._viewGroup = viewGroup

        this.initFramework()
    }

    // 场景加载后回调
    public static onSceneLoaded() {
        this.initFramework()
    }


    // 递归显示节点信息
    public static showNode(node: cc.Node, sep: string = '', depth: number = 0, depthMax: number = 4) {
        console.log(sep + node.name + ':' + node.zIndex + ':' + node.active)
        if (node.childrenCount <= 0) return

        depth++
        if (depth >= depthMax) return

        node.children.forEach(child => this.showNode(child, sep + '\t', depth, depthMax))
    }


    // 初始化框架
    private static initFramework() {
        LayerMgr.init(this._viewGroup)

        UIMgr.init(this._uiMain)
        PanelMgr.init()
    }
}
